//
//  BodyTestViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/25.
//



#import "BodyTestViewController.h"
#import "SubmitLoadingView.h"
#import "MaiXingTuViewController.h"

@interface BodyTestViewController ()
@property(nonatomic,strong) UIImageView *scanImage;
@property(nonatomic,strong) NSTimer *timer;
@end

@implementation BodyTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHideNavigationBar = YES;
    [self.view az_setGradientBackgroundWithColors:@[HexColor(@"#091E4D"),HexColor(@"#2761BB")] locations:@[@0.0,@1.0] startPoint:CGPointMake(0.5, 1) endPoint:CGPointMake(0.5, 1)];
}
- (void)dealloc {
    [self.timer invalidate];
    self.timer = nil;
}

- (void)initSubviews {
    [super initSubviews];
    
    UIImageView *backImage = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_wang")];
    backImage.frame = CGRectMake(0, kScreenHeight/2 - 100, kScreenWidth, kScreenWidth/1.8);
    [self.view addSubview:backImage];
    
    UIImageView *topImage = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_kuang")];
    topImage.frame = CGRectMake(26, kScreenHeight - ((kScreenWidth - 52)/0.74 + 206) , kScreenWidth - 52, (kScreenWidth - 52)/0.74);
    [self.view addSubview:topImage];
    
    UIImageView *dizuo = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_dizuo")];
    [topImage addSubview:dizuo];
    [dizuo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(topImage).offset(32);
        make.bottom.right.mas_equalTo(topImage).offset(-32);
        make.height.equalTo(@(70));
    }];
    
    UIImageView *gifImage = [[UIImageView alloc]initWithImage:[UIImage qmui_animatedImageNamed:@"shenti.gif"]];
    gifImage.frame = CGRectMake(0, 30, topImage.width, topImage.width);
    [topImage addSubview:gifImage];
    
    UIImageView *scanImage = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_saomiao")];
    scanImage.frame = CGRectMake(0, -60, topImage.width, 90);
    CGAffineTransform transform= CGAffineTransformMakeRotation(M_PI);
    scanImage.transform = transform;//旋转
    [topImage addSubview:scanImage];
    self.scanImage = scanImage;
    [self.scanImage.layer addAnimation:[self moveY:3.0f Y:[NSNumber numberWithFloat:topImage.height - 40]] forKey:nil];
    
    
    MyLinearLayout *bottom = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    bottom.myHorzMargin = 0;
    bottom.padding = UIEdgeInsetsMake(0, 15, 0, 15);
    bottom.myHeight = 206;
    bottom.myBottom = 0;
    [self.view addSubview:bottom];
    
    MyLinearLayout *top = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    top.myHorzMargin = 0;
    top.gravity = MyGravity_Vert_Center | MyGravity_Horz_Between;
    top.myHeight = 30;
    [bottom addSubview:top];
    
    NSArray *array = @[@"经络",@"穴位",@"电位"];
    for (int i = 0; i < array.count; i++) {
        UILabel *content = [UILabel createLabelText:array[i] font:UIFontMake(12) textColor:HexColor(@"#1FAEFF")];
        content.myHeight = kAutoHeight;
        content.myWidth = (kScreenWidth - 30)/3.0;
        content.textAlignment = NSTextAlignmentCenter;
        [top addSubview:content];
    }
    
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.myHorzMargin = 0;
    scrollView.myHeight = 100;
    [bottom addSubview:scrollView];
    
    MyLinearLayout *scrollLay = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    scrollLay.myHorzMargin = 0;
    scrollLay.myHeight = kAutoHeight;
    [scrollView addSubview:scrollLay];
    
    
    
    NSArray *content = @[
        @[@"手少阴心经",@"青灵",@"0.5645674"],
        @[@"手少阴心经",@"青灵",@"0.5645674"],
        @[@"手少阴心经",@"青灵",@"0.5645674"],
        @[@"手少阴心经",@"青灵",@"0.5645674"],
        @[@"手少阴心经",@"青灵",@"0.5645674"],
    ];
    for (int j = 0; j < content.count; j++) {
        NSArray *item = content[j];
        
        MyLinearLayout *itemLay = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        itemLay.myHorzMargin = 0;
        itemLay.gravity = MyGravity_Vert_Center | MyGravity_Horz_Between;
        itemLay.myHeight = 30;
        [scrollLay addSubview:itemLay];
        
        for (int i = 0; i < item.count; i++) {
            UILabel *content = [UILabel createLabelText:item[i] font:UIFontMake(13) textColor:COLOR_4];
            content.myHeight = 30;
            content.myWidth = (kScreenWidth - 30)/3.0;
            content.textAlignment = NSTextAlignmentCenter;
            [itemLay addSubview:content];
        }
    }
    
    
    UIButton *stopBtn = [UIButton createButtonText:@"停止检测" font:UIFontMake(14) textColor:COLOR_4];
    stopBtn.myHorzMargin = 0;
    stopBtn.myHeight = 46;
    stopBtn.myTop = 30;
    ViewCorner(stopBtn, 23);
    [stopBtn az_setGradientBackgroundWithColors:@[HexColor(@"#2068DA"),HexColor(@"#4C86E1")] locations:@[@0.0,@1.0] startPoint:CGPointMake(0.5,0) endPoint:CGPointMake(0.5, 1)];
    [stopBtn addTarget:self action:@selector(stopBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bottom addSubview:stopBtn];
    __block CGFloat y = 0.0;
    self.timer = [NSTimer timerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        y += 30;
        if(y > scrollView.contentSize.height) y = 0.0;
        [UIView animateWithDuration:1 animations:^{
            scrollView.contentOffset = CGPointMake(0, y);
        }];
    }];
    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
}

- (void)stopBtnClick {
//    [self.navigationController popViewControllerAnimated:YES];
    
    SubmitLoadingView *resultView = [[SubmitLoadingView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 120, 245)];
    resultView.text = @"正在描绘脉波检测图形";
    WeakSelf
    [resultView setLoadComplateBlock:^{
        [weakSelf.zh_popupController dismiss];
        MaiXingTuViewController *vc = MaiXingTuViewController.new;
        [weakSelf showViewController:vc sender:weakSelf];
    }];
    self.zh_popupController = [zhPopupController new];
    self.zh_popupController.layoutType = zhPopupLayoutTypeCenter;
    self.zh_popupController.allowPan = NO;
    self.zh_popupController.maskAlpha = 0.7;
    self.zh_popupController.dismissOnMaskTouched = YES;
    [self.zh_popupController presentContentView:resultView];
    
}

#pragma mark =====横向、纵向移动===========

-(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y{
    CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    animation.toValue = y;
    animation.duration = time;
    animation.removedOnCompletion = NO;//yes的话，又返回原位置了。
    animation.repeatCount = MAXFLOAT;
    animation.fillMode = kCAFillModeForwards;
    return animation;
}
@end
